<template>
  <div class="login-container">
    <!-- 背景装饰 -->
    <div class="background-decoration">
      <div class="floating-shapes">
        <div class="shape shape-1"></div>
        <div class="shape shape-2"></div>
        <div class="shape shape-3"></div>
        <div class="shape shape-4"></div>
      </div>
      <div class="floating-hearts">
        <div class="heart heart-1">❤</div>
        <div class="heart heart-2">❤</div>
        <div class="heart heart-3">❤</div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="login-content">
      <!-- 左侧卡通厨师区域 -->
      <div class="chef-section">
        <div class="chef-character">
          <div class="chef-head">
            <div class="chef-face">
              <div class="chef-eyes">
                <div class="eye eye-left">
                  <div class="eye-sparkle"></div>
                </div>
                <div class="eye eye-right">
                  <div class="eye-sparkle"></div>
                </div>
              </div>
              <div class="chef-cheeks">
                <div class="cheek cheek-left"></div>
                <div class="cheek cheek-right"></div>
              </div>
              <div class="chef-smile"></div>
              <div class="chef-nose"></div>
            </div>
            <div class="chef-hair">
              <div class="hair-curls">
                <div class="curl curl-1"></div>
                <div class="curl curl-2"></div>
                <div class="curl curl-3"></div>
              </div>
            </div>
            <div class="chef-hat">
              <div class="hat-base"></div>
              <div class="hat-top"></div>
              <div class="hat-ribbon"></div>
              <div class="hat-dots">
                <div class="dot dot-1"></div>
                <div class="dot dot-2"></div>
                <div class="dot dot-3"></div>
              </div>
            </div>
          </div>
          <div class="chef-body">
            <div class="chef-shirt">
              <div class="shirt-collar"></div>
              <div class="shirt-buttons">
                <div class="button button-1"></div>
                <div class="button button-2"></div>
                <div class="button button-3"></div>
              </div>
            </div>
            <div class="chef-apron">
              <div class="apron-pocket"></div>
              <div class="apron-strings">
                <div class="string string-left"></div>
                <div class="string string-right"></div>
              </div>
            </div>
            <div class="chef-arms">
              <div class="arm arm-left">
                <div class="hand hand-left">
                  <div class="plate">
                    <div class="food-item food-1">🍕</div>
                    <div class="food-item food-2">🍜</div>
                    <div class="food-item food-3">🍣</div>
                  </div>
                </div>
              </div>
              <div class="arm arm-right">
                <div class="hand hand-right">
                  <div class="spatula">🥄</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="welcome-text">
          <h2>欢迎来到</h2>
          <h1>餐饮管理系统</h1>
          <p>让美食管理变得简单有趣</p>
        </div>
      </div>

      <!-- 右侧登录表单 -->
      <div class="login-form-section">
        <div class="login-form-container">
          <div class="form-header">
            <h3>员工登录</h3>
            <p>请输入您的员工信息</p>
          </div>
          
          <el-form 
            ref="loginFormRef" 
            :model="loginForm" 
            :rules="loginRules" 
            class="login-form"
            @submit.prevent="handleLogin"
          >
            <el-form-item prop="employeeId">
              <el-input
                v-model="loginForm.name"
                placeholder="请输入员工姓名"
                size="large"
                prefix-icon="User"
                class="custom-input"
              />
            </el-form-item>
            
            <el-form-item prop="password">
              <el-input
                v-model="loginForm.password"
                type="password"
                placeholder="请输入密码"
                size="large"
                prefix-icon="Lock"
                class="custom-input"
                show-password
              />
            </el-form-item>
            
            <el-form-item>
              <el-button
                type="primary"
                size="large"
                class="login-button"
                :loading="loading"
                @click="handleLogin"
              >
                <span v-if="!loading">登录</span>
                <span v-else>登录中...</span>
              </el-button>
            </el-form-item>
          </el-form>
          
          <div class="form-footer">

          </div>
        </div>
      </div>
    </div>

    <!-- 底部装饰 -->
    <div class="bottom-decoration">
      <div class="food-icons">
        <div class="food-icon">🍕</div>
        <div class="food-icon">🍜</div>
        <div class="food-icon">🍣</div>
        <div class="food-icon">🍰</div>
        <div class="food-icon">☕</div>
      </div>
    </div>
  </div>
</template>
<script setup>import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import axios from 'axios'

const router = useRouter()
const loginFormRef = ref(null)
const loading = ref(false)

const loginForm = reactive({
  name: '',
  password: ''
})

// 确保验证规则与实际字段一致
const loginRules = {
  name: [
    { required: true, message: '请输入员工姓名', trigger: 'blur' },
    { min: 3, max: 20, message: '员工姓名长度在3到20个字符', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 20, message: '密码长度在6到20个字符', trigger: 'blur' }
  ]
}
const handleLogin = async () => {
  if (!loginFormRef.value) return

  try {
    await loginFormRef.value.validate()
    loading.value = true

    const response = await axios.post('/api/login/user', {
      name: loginForm.name,
      password: loginForm.password
    })

    // 修改判断条件以匹配实际返回结构
    if (response.data.code === 200) {
      // 保存登录状态
      localStorage.setItem('token', response.data.data.token)
      localStorage.setItem('employeeId', response.data.data.employeeId)
      localStorage.setItem('employeeName', response.data.data.name)

      ElMessage.success('登录成功！欢迎回来')
      await router.push('/dashboard')
    } else {
      ElMessage.error(response.data.message || '登录失败，请重试')
    }
  } catch (error) {
    console.error('登录请求失败:', error)
    if (error.response) {
      ElMessage.error(error.response.data.message || '登录失败：' + error.response.status)
    } else if (error.request) {
      ElMessage.error('网络错误，请检查服务器连接')
    } else {
      ElMessage.error('登录请求失败：' + error.message)
    }
  } finally {
    loading.value = false
  }
}


</script>


<style scoped>
.login-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* 背景装饰 */
.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.floating-shapes {
  position: absolute;
  width: 100%;
  height: 100%;
}

.shape {
  position: absolute;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  animation: float 6s ease-in-out infinite;
}

.shape-1 {
  width: 80px;
  height: 80px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.shape-2 {
  width: 120px;
  height: 120px;
  top: 20%;
  right: 15%;
  animation-delay: 2s;
}

.shape-3 {
  width: 60px;
  height: 60px;
  bottom: 20%;
  left: 20%;
  animation-delay: 4s;
}

.shape-4 {
  width: 100px;
  height: 100px;
  bottom: 10%;
  right: 10%;
  animation-delay: 1s;
}

.floating-hearts {
  position: absolute;
  width: 100%;
  height: 100%;
}

.heart {
  position: absolute;
  color: #ff6b6b;
  font-size: 24px;
  animation: heartBeat 3s ease-in-out infinite;
}

.heart-1 {
  top: 15%;
  right: 25%;
  animation-delay: 0s;
}

.heart-2 {
  top: 35%;
  right: 35%;
  animation-delay: 1s;
}

.heart-3 {
  top: 55%;
  right: 20%;
  animation-delay: 2s;
}

/* 主要内容区域 */
.login-content {
  display: flex;
  align-items: center;
  gap: 60px;
  z-index: 10;
  position: relative;
}

/* 左侧厨师区域 */
.chef-section {
  text-align: center;
  color: #2c3e50;
}

.chef-character {
  width: 200px;
  height: 280px;
  position: relative;
  margin: 0 auto 30px;
}

.chef-head {
  position: relative;
  width: 100px;
  height: 100px;
  background: #ffeaa7;
  border-radius: 50%;
  margin: 0 auto;
  border: 3px solid #fdcb6e;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.chef-face {
  position: relative;
  width: 100%;
  height: 100%;
}

.chef-eyes {
  position: absolute;
  top: 35px;
  width: 100%;
  display: flex;
  justify-content: space-around;
}

.eye {
  width: 18px;
  height: 18px;
  background: #2c3e50;
  border-radius: 50%;
  position: relative;
  border: 2px solid #34495e;
}

.eye::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 6px;
  height: 6px;
  background: white;
  border-radius: 50%;
}

.eye-sparkle {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  background: #f1c40f;
  border-radius: 50%;
  animation: sparkle 1.5s infinite;
}

.chef-cheeks {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 20px;
  display: flex;
  justify-content: space-between;
}

.cheek {
  width: 12px;
  height: 12px;
  background: #ff7675;
  border-radius: 50%;
  opacity: 0.8;
}

.cheek-left {
  left: -5px;
}

.cheek-right {
  right: -5px;
}

.chef-smile {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  width: 35px;
  height: 18px;
  border: 3px solid #e17055;
  border-top: none;
  border-radius: 0 0 35px 35px;
}

.chef-nose {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: #fd79a8;
  border-radius: 50%;
}

.chef-hair {
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 40px;
}

.hair-curls {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 30px;
  display: flex;
  justify-content: space-around;
}

.curl {
  width: 12px;
  height: 12px;
  background: #a29bfe;
  border-radius: 50%;
  animation: float 3s ease-in-out infinite;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.curl-1 { animation-delay: 0s; }
.curl-2 { animation-delay: 0.5s; }
.curl-3 { animation-delay: 1s; }

.chef-hat {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 50px;
}

.hat-base {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #ff9ff3, #f368e0);
  border-radius: 50%;
  border: 3px solid #e84393;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.hat-top {
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  width: 45px;
  height: 45px;
  background: linear-gradient(135deg, #f368e0, #e84393);
  border-radius: 50%;
  border: 3px solid #ff9ff3;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}

.hat-ribbon {
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 25px;
  height: 25px;
  background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  border-radius: 50%;
  border: 2px solid #ff5252;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.hat-dots {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 15px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.dot {
  width: 6px;
  height: 6px;
  background: #fff;
  border-radius: 50%;
  border: 2px solid #e84393;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.dot-1 { 
  animation: wiggle 1s ease-in-out infinite; 
  background: #ff9ff3;
}
.dot-2 { 
  animation: wiggle 1.2s ease-in-out infinite; 
  background: #fdcb6e;
}
.dot-3 { 
  animation: wiggle 1.4s ease-in-out infinite; 
  background: #a29bfe;
}

.chef-body {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 140px;
}

.chef-shirt {
  width: 100%;
  height: 80px;
  background: #a8e6cf;
  border-radius: 20px;
  border: 3px solid #88d8a3;
  position: relative;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.shirt-collar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 45px;
  height: 25px;
  background: #74b9ff;
  border-radius: 10px 10px 0 0;
  border: 2px solid #0984e3;
}

.shirt-buttons {
  position: absolute;
  top: 25px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 25px;
  display: flex;
  justify-content: space-around;
}

.button {
  width: 12px;
  height: 12px;
  background: #e84393;
  border-radius: 50%;
  border: 2px solid #fd79a8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.button-1 {
  left: -5px;
}
.button-2 {
  left: 5px;
}
.button-3 {
  right: 5px;
}

.chef-apron {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 110px;
  height: 100px;
  background: #fd79a8;
  border-radius: 20px;
  border: 3px solid #e84393;
  position: relative;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.apron-pocket {
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  width: 35px;
  height: 35px;
  background: #fdcb6e;
  border-radius: 50%;
  border: 2px solid #e17055;
}

.apron-strings {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 25px;
  display: flex;
  justify-content: space-around;
}

.string {
  width: 6px;
  height: 12px;
  background: #2c3e50;
  border-radius: 3px;
}

.string-left {
  left: -10px;
}
.string-right {
  right: -10px;
}

.chef-arms {
  position: absolute;
  top: 25px;
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.arm {
  width: 25px;
  height: 50px;
  background: #ffeaa7;
  border-radius: 12px;
  position: relative;
  border: 2px solid #fdcb6e;
}

.arm-left {
  left: -15px;
}

.arm-right {
  right: -15px;
}

.hand {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  background: #ffeaa7;
  border-radius: 50%;
  border: 2px solid #fdcb6e;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.hand-left {
  top: -8px;
}

.hand-right {
  top: -8px;
}

.plate {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 45px;
  height: 45px;
  background: #f8f9fa;
  border-radius: 50%;
  border: 3px solid #dee2e6;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.food-item {
  font-size: 12px;
  animation: bounce 2s ease-in-out infinite;
}

.food-item:nth-child(1) { animation-delay: 0s; }
.food-item:nth-child(2) { animation-delay: 0.3s; }
.food-item:nth-child(3) { animation-delay: 0.6s; }

.spatula {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  animation: rotate 3s ease-in-out infinite;
}

.welcome-text h1 {
  font-size: 28px;
  margin: 10px 0;
  color: #2c3e50;
  font-weight: bold;
}

.welcome-text h2 {
  font-size: 20px;
  margin: 0;
  color: #34495e;
}

.welcome-text p {
  font-size: 16px;
  color: #7f8c8d;
  margin: 10px 0;
}

/* 右侧登录表单 */
.login-form-section {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.login-form-container {
  width: 350px;
}

.form-header {
  text-align: center;
  margin-bottom: 30px;
}

.form-header h3 {
  font-size: 24px;
  color: #2c3e50;
  margin: 0 0 8px 0;
  font-weight: bold;
}

.form-header p {
  color: #7f8c8d;
  margin: 0;
  font-size: 14px;
}

.login-form .el-form-item {
  margin-bottom: 20px;
}

.custom-input {
  border-radius: 12px;
}

.custom-input :deep(.el-input__wrapper) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.custom-input :deep(.el-input__wrapper:hover) {
  border-color: #3498db;
  box-shadow: 0 4px 12px rgba(52, 152, 219, 0.2);
}

.custom-input :deep(.el-input__wrapper.is-focus) {
  border-color: #3498db;
  box-shadow: 0 4px 16px rgba(52, 152, 219, 0.3);
}

.login-button {
  width: 100%;
  height: 50px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: bold;
  background: linear-gradient(135deg, #3498db, #2980b9);
  border: none;
  box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
  transition: all 0.3s ease;
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

.form-footer {
  margin-top: 30px;
  text-align: center;
}

.demo-info {
  background: rgba(52, 152, 219, 0.1);
  border-radius: 12px;
  padding: 15px;
  border: 1px solid rgba(52, 152, 219, 0.2);
}

.demo-info p {
  margin: 5px 0;
  color: #34495e;
  font-size: 14px;
}

.demo-id, .demo-password {
  color: #e74c3c;
  font-weight: bold;
}

/* 底部装饰 */
.bottom-decoration {
  position: absolute;
  bottom: 20px;
  left: 0;
  width: 100%;
  text-align: center;
}

.food-icons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.food-icon {
  font-size: 24px;
  animation: bounce 2s ease-in-out infinite;
}

.food-icon:nth-child(1) { animation-delay: 0s; }
.food-icon:nth-child(2) { animation-delay: 0.2s; }
.food-icon:nth-child(3) { animation-delay: 0.4s; }
.food-icon:nth-child(4) { animation-delay: 0.6s; }
.food-icon:nth-child(5) { animation-delay: 0.8s; }

/* 动画 */
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-20px); }
}

@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes sparkle {
  0%, 100% { opacity: 0.8; transform: scale(1); }
  50% { opacity: 0; transform: scale(1.2); }
}

@keyframes rotate {
  0%, 100% { transform: translateX(-50%) rotate(0deg); }
  50% { transform: translateX(-50%) rotate(10deg); }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* 添加一些悬停效果 */
.chef-character:hover .chef-head {
  animation: wiggle 0.5s ease-in-out;
}

.chef-character:hover .eye {
  animation: pulse 1s ease-in-out infinite;
}

.chef-character:hover .chef-hat {
  animation: float 2s ease-in-out infinite;
}

.chef-character:hover .chef-hat .hat-top {
  animation: rotate 1s ease-in-out infinite;
}

.chef-character:hover .chef-hat .hat-dots .dot {
  animation: bounce 0.8s ease-in-out infinite;
}

.chef-character:hover .plate {
  animation: pulse 1.5s ease-in-out infinite;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .login-content {
    flex-direction: column;
    gap: 30px;
    padding: 20px;
  }
  
  .chef-character {
    width: 150px;
    height: 180px;
  }
  
  .chef-head {
    width: 90px;
    height: 90px;
  }
  
  .chef-body {
    top: 80px;
    width: 100px;
    height: 80px;
  }
  
  .login-form-container {
    width: 100%;
    max-width: 350px;
  }
  
  .login-form-section {
    padding: 30px 20px;
  }
}
</style> 